local skinchange = fk.CreateSkill{
  name = "skinchange",
  tags = {Skill.Permanent},
}
Fk:loadTranslationTable{
  ["skinchange"] = "换肤",
  [":skinchange"] = "更换原画<br/>--我举报，有人开换肤",
  ["#skinchange"] = "选择一个更换(可以右键或长按自选)",
  ["change_general"] = "更换主将原画",
  ["change_deputyGeneral"] = "更换副将原画",

}

skinchange:addEffect("active", {
  global = true, 
  is_delay_effect = true,
  mute = true,
  prompt = "#skinchange",
  card_num = 0,
  max_target_num = 1,
  can_use = function(self, player)
    return true
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 
  end,
  on_use = function(self, room, effect)
    local generals = room:getNGenerals(4)
    local player = effect.from
    local target = #effect.tos > 0 and effect.tos[1] or player
    local result = room:askToCustomDialog( player, {
      skill_name = skinchange.name,
      qml_path = "packages/blank/qml/ChooseSkinBox.qml",
      extra_data = {
        generals,
        {"OK"},
        "#skinchange",
        {"Cancel"},
        1,
        1,
      },
    })    
    local general = ""
    if result == "" or result.choice == "Cancel" then return end
    general = result.cards[1]
    if general == "skinchange__tips" then 
      local hidden = {"sexy__1__dongzhuo_zuo","sexy__1__dongzhuo_you","sexy__1__wangyi","sexy__1__caohua","sexy__1__zhangchu",
      "sexy__1__caifuren","sexy__2__caifuren","sexy__3__caifuren","sexy__4__caifuren","sexy__5__caifuren"}
      general = hidden[math.random(1,#hidden)] 
    end
    if target.deputyGeneral == "" then
      target.general = general
      room:broadcastProperty(target, "general")
    else
      local choice = room:askToChoice(player, {
        choices = {"change_general","change_deputyGeneral"},
        skill_name = skinchange.name,
      })
      if choice == "change_general" then
        target.general = general
        room:broadcastProperty(target, "general")
      else
        target.deputyGeneral = general
        room:broadcastProperty(target, "deputyGeneral")
      end
    end
    room:returnToGeneralPile(generals)
  end,
})


return skinchange
